package net.aaa.hotel.controller;

import net.aaa.hotel.dao.DingDanDao;
import net.aaa.hotel.dao.TXufangDao;
import net.aaa.hotel.util.LayuiTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/DingDan")
public class DingDanController {
    /**
     *
     */
    @Autowired
    private DingDanDao dingDanDao;
    @Autowired
    TXufangDao xufangDao;

    @RequestMapping("/query")
    @ResponseBody
    public LayuiTable query(HttpSession session){
        Map cuser=(Map)session.getAttribute("cuser");

        List<Map> query  =dingDanDao.query(cuser);

        return new LayuiTable(query.size(), query);
    }

    @RequestMapping("/qqq")
    @ResponseBody
    public List<Map> qqq(Integer id){
        System.out.println(id);
        List<Map>  qqq =dingDanDao.qqq(id);
        int dcount = qqq.size();
        for (int i = 0; i < dcount; i++) {
            Map map = qqq.get(i);
            Integer flag = Integer.parseInt(qqq.get(i).get("rstatus")+"");
            if(flag == 1){
                // 根据入住id到续房表里查找对应id的最大离开时间
                List<Map> record = xufangDao.getRecordByRZid(qqq.get(i).get("id") + "");
                map.put("leavedate",record.get(0).get("endtime"));
            }
        }
        System.out.println(qqq.size());
        return qqq;
    }

}
